package lt.marsrutai.mobile.android.util;

import java.io.IOException;
import java.io.InputStream;

public class CalculatingInputStream extends InputStream {

    private InputStream is;
    private Integer readCount = 0;

    public CalculatingInputStream(InputStream is) {
        this.is = is;
    }
    
    public Integer getReadCount() {
        return readCount;
    }

    public int available() throws IOException {
        return is.available();
    }

    public void close() throws IOException {
        is.close();
    }

    public void mark(int readlimit) {
        is.mark(readlimit);
    }

    public boolean markSupported() {
        return is.markSupported();
    }

    @Override
    public int read() throws IOException {
        int r = is.read();
        readCount += r;
        return r;
    }

    public int read(byte[] b) throws IOException {
        int r = is.read(b);
        readCount += r;
        return r;
    }
    
    public int read(byte[] b, int off, int len) throws IOException {
        int r = is.read(b, off, len);
        readCount += r;
        return r;
    }
    
    public void reset() throws IOException {
        is.reset();
    }
    
    public long skip(long n) throws IOException {
        return is.skip(n);
    }
}
